package com.sgb.zhaocai.view.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;
import com.sgb.zhaocai.BR;
import com.sgb.zhaocai.R;
import com.sgb.zhaocai.entity.PickInvitedList;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import com.swgk.core.util.DateUtils;

import java.util.List;

public class PickInvitedListAdapter extends BaseRecycleAdapter<PickInvitedList> {

    private TextView tvType;
    private TextView tvNatureName;
    private TextView invitedState;
    private TextView tvApplyState;
    private TextView tvBusinessTitle;
    private String fromWhere = "1";
    private IChildClick iChildClick;
    private TextView tvCreateTime;
    private View line;

    public PickInvitedListAdapter(Context context, List<PickInvitedList> datas) {
        super(context, R.layout.item_pick_invited_list, datas);
    }

    @Override
    public void convert(ItemViewHolder holder, final PickInvitedList entity) {
        holder.setBinding(BR.viewModel, entity);

        tvType = holder.itemView.findViewById(R.id.tv_type);
        tvNatureName = holder.itemView.findViewById(R.id.tv_nature_Name);
        tvApplyState = holder.itemView.findViewById(R.id.tv_apply_state);
        invitedState = holder.itemView.findViewById(R.id.invited_state);
        tvBusinessTitle = holder.itemView.findViewById(R.id.tv_business_title);
        tvCreateTime = holder.itemView.findViewById(R.id.tv_create_time);
        line = holder.itemView.findViewById(R.id.line);

        tvNatureName.setText(entity.getCustomerNatureName());

        if (entity.getInviteMethod() == 1) {  //1邀请公司   2邀请个人
            tvType.setText("企业");
        } else if (entity.getInviteMethod() == 2) {
            tvType.setText("个人");
        }
        if ("1".equals(fromWhere)) {   //招标
            tvBusinessTitle.setText(entity.getTenderName());

            //招标状态=招标报名，且报名状态=未报名 时显示，否则不显示该按钮
            if (entity.getStatus() == 0) {
                tvApplyState.setText("未报名");
                invitedState.setVisibility(View.VISIBLE);
            } else if (entity.getStatus() == 1) {
                tvApplyState.setText("已报名");
                invitedState.setVisibility(View.GONE);
            }

            if (TextUtils.isEmpty(entity.getCreateTime())){
                tvCreateTime.setText("");
            }else{
                tvCreateTime.setText(DateUtils.stampToMinute(entity.getCreateTime()));
            }

        } else if ("2".equals(fromWhere)) {  //竞价
            tvBusinessTitle.setText(entity.getBidName());

            //竞价状态=竞价中，且 报价状态=未报价  时显示
            if ("竞价中".equals(entity.getStateName()) && entity.getStatus() == 0) {
                line.setVisibility(View.VISIBLE);
                invitedState.setVisibility(View.VISIBLE);
            } else {
                line.setVisibility(View.GONE);
                invitedState.setVisibility(View.GONE);
            }
            if (entity.getStatus() == 0) {
                tvApplyState.setText("未报价");
            } else if (entity.getStatus() == 1) {
                tvApplyState.setText("已报价");
            }

            if (TextUtils.isEmpty(entity.getCreateTime())){
                tvCreateTime.setText("");
            }else{
                tvCreateTime.setText(DateUtils.stampToMinute(entity.getCreateTime()));
            }

        }

        invitedState.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                iChildClick.onClick(entity);
            }
        });

    }

    public interface IChildClick {
        void onClick(PickInvitedList pickInvitedList);
    }

    public void onIChildClick(IChildClick iChildClick) {
        this.iChildClick = iChildClick;
    }

    public void setFromWhere(String fromWhere) {
        this.fromWhere = fromWhere;
    }
}
